﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleList.aspx.cs" Inherits="Atomic.Web.Pages.Sys.RoleList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        $(function () {
            $('#roleList').datagrid({
                url: '/Handlers/Sys/RoleHandler.ashx/?method=GetRoleList',
                singleSelect: true,
                columns: [[
	                { field: 'ID', title: '编号', width: 60 },
	                { field: 'Name', title: '角色名', width: 150 },
                    { field: 'Enabled', title: '启用', width: 50,
                        formatter: function (v) {
                            if (v) {
                                return '是';
                            } else {
                                return '<span style="color:#f00;">否<span>';
                            }
                        }
                    },
	                { field: 'Description', title: '描述', width: 250 }
                ]],
                toolbar: [
                    {
                        text: '新建',
                        iconCls: 'icon-add',
                        handler: function () {
                            $('#roleEditorWindow').window('open');
                            $('#roleEditorWindow').window('refresh', 'RoleEditor.aspx');
                        }
                    },
                    {
                        text: '编辑',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var selected = $('#roleList').datagrid('getSelected');
                            if (selected == null) {
                                $.messager.alert('提示信息', '请选择需要编辑的项', 'info');
                                return;
                            }
                            $('#roleEditorWindow').window('open');
                            $('#roleEditorWindow').window('refresh', 'RoleEditor.aspx?ID=' + selected.ID);
                        }
                    },
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: function () {
                            var selected = $('#roleList').datagrid('getSelected');
                            if (selected == null) {
                                $.messager.alert('提示信息', '请选择需要删除的项', 'info');
                                return;
                            }
                            $.messager.confirm('提示信息', '确定删除选中项？', function (b) {
                                if (b) {
                                    //提交删除
                                    $.post('/Handlers/Sys/RoleHandler.ashx/?method=RemoveRole',
                                    {
                                        ID: selected.ID
                                    },
                                    function (data) {
                                        if (data.Success) {
                                            $('#roleList').datagrid('reload');
                                        } else {
                                            $.messager.alert('提示信息', data.Message, 'info');
                                        }
                                    },
                                    'json');
                                }
                            });
                        }
                    },
                    {
                        text: '权限配置',
                        iconCls: 'icon-function',
                        handler: function () {
                            var selected = $('#roleList').datagrid('getSelected');
                            if (selected == null) {
                                $.messager.alert('提示信息', '请选择一个角色', 'info');
                                return;
                            }
                            $('#roleFunEditorWindow').window('open');
                            $('#roleFunEditorWindow').window('refresh', 'ResourceListForRole.aspx?RoleID=' + selected.ID);
                        }
                    }
                ]
            });

            //初始化功能编辑窗口
            $('<div id="roleEditorWindow"></div>').appendTo('body').window({
                href: 'javascript:void(0);',
                title: '新建/编辑角色',
                width: 320,
                top: $(window).height() * 0.25,
                closed: true
            });
            //初始化权限配置窗口
            $('<div id="roleFunEditorWindow"></div>').appendTo('body').window({
                href: 'javascript:void(0);',
                title: '角色权限配置',
                closed: true,
                maximized: true //初始最大化
            });
        });
        //编辑角色信息成功后处理
        function OnRoleEditSuccess() {
            $('#roleEditorWindow').window('close');
            $('#roleList').datagrid('reload');
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="roleList">
    </div>
    </form>
</body>
</html>
